﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Input.Manipulations;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Wintellect.Touch.Views
{
    public partial class TouchChildWindow : ChildWindow
    {
        public TouchChildWindow()
        {
            InitializeComponent();
        }

        private void HandleCloseButtonClick(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
        }

        private void TouchShapeBehavior_ManipulationStarted(Object sender, Manipulation2DStartedEventArgs e)
        {
            var senderShape = (Shape)sender;
            senderShape.Tag = senderShape.Fill;
            senderShape.Fill = new SolidColorBrush(Colors.Yellow);
        }

        private void TouchShapeBehavior_ManipulationDelta(Object sender, Manipulation2DDeltaEventArgs e)
        {
            var senderShape = (Shape)sender;
            if (senderShape.RenderTransform is CompositeTransform)
            {
                var compositeTransform = (CompositeTransform)senderShape.RenderTransform;
                compositeTransform.TranslateX += e.Delta.TranslationX;
                compositeTransform.TranslateY += e.Delta.TranslationY;
            }
            else if (senderShape.RenderTransform is TranslateTransform)
            {
                var translateTransform = (TranslateTransform)senderShape.RenderTransform;
                translateTransform.X += e.Delta.TranslationX;
                translateTransform.Y += e.Delta.TranslationY;
            }
        }

        private void TouchShapeBehavior_ManipulationCompleted(Object sender, Manipulation2DCompletedEventArgs e)
        {
            var senderShape = (Shape)sender;
            //TODO: This should really be done at the end of inertia, otherwise it will take the original color and keep moving...
            senderShape.Fill = senderShape.Tag as Brush;
        }
    }
}

